#ifndef WATCHER_H_
#define WATCHER_H_
#include <netinet/in.h>
#include "g_headers.h"
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stdint.h>

using namespace std;


struct event
{
	uint8_t option;
	string path;
};

class Watcher
{
	public:
                Watcher(bool &p_update);
		void watch(vector<string>& all_path);
		void process_events();
		void cexit();
		void set_usr_info(string& usr, string& pwd);
                string get_user() {return usr;}

	public:
		int ctl_sock;  //控制信号
//		int tsf_sock;  //传输文件
		struct sockaddr_in srv_ctl;
		struct sockaddr_in srv_tsf;
	
	private:
		int fd_nofity;
		int sem_id;		
		map<int,string> watch_list;	
		queue<struct event*> event_queue;
		string usr;
		string pwd;
                bool &updated;
		
	private:
		void cre_or_del(int option, struct event* event);
		int get_sock(int flag);
		void print_event(struct event* event);
		bool file_filter(const char* name);
		bool is_dir(int wd, const char* name);
		void init_sock(int kind,struct sockaddr_in* sock_addr);
		void build_event(int option, string& path,
						struct event*& event);
		void add_watch(vector<string>& all_path);
		void update(struct event* event);
};

#endif
